<?php
class GroupPostCommentsController extends AppController {

	var $name = 'GroupPostComments';
	var $uses = array('GroupPostComment','GroupPost');

	function index() {
		$this->GroupPostComment->recursive = 0;
		$this->set('groupPostComments', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid group post comment', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('groupPostComment', $this->GroupPostComment->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->GroupPostComment->create();
			if ($this->GroupPostComment->save($this->data)) {
				$this->Session->setFlash(__('The group post comment has been saved', true));
				$this->GroupPost->id = $this->data['GroupPostComment']['group_post_id'];
				$this->GroupPost->saveField('upated',date("Y-m-d H:i:s"));
				$this->redirect($this->referer());
			} else {
				$this->Session->setFlash(__('The group post comment could not be saved. Please, try again.', true));
			}
		}
		$groupPosts = $this->GroupPostComment->GroupPost->find('list');
		$users = $this->GroupPostComment->User->find('list');
		$groups = $this->GroupPostComment->Group->find('list');
		$this->set(compact('groupPosts', 'users', 'groups'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid group post comment', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->GroupPostComment->save($this->data)) {
				$this->Session->setFlash(__('The group post comment has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The group post comment could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->GroupPostComment->read(null, $id);
		}
		$groupPosts = $this->GroupPostComment->GroupPost->find('list');
		$users = $this->GroupPostComment->User->find('list');
		$groups = $this->GroupPostComment->Group->find('list');
		$this->set(compact('groupPosts', 'users', 'groups'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for group post comment', true));
			$this->cakeError('access');
		}
		if ($this->GroupPostComment->delete($id)) {
			$this->Session->setFlash(__('Group post comment deleted', true));
			$this->redirect($this->referer());
		}
		$this->Session->setFlash(__('Group post comment was not deleted', true));
		$this->cakeError('access');
	}
}
?>